package com.example.demo.refactor.price;

import java.util.Arrays;

/**
 * @author dhc
 * @title: Emeun
 * @projectName demo
 * @description: TODO
 * @date 2020-10-09 14:26
 */
public enum PriceEnum {
    /**
     * 接受
     */
    CHILDRENS(new ChildrensPrice(),
            2),
    /**
     * 拒绝
     */
    NEWRELEASE(new NewReleasePrice(), 1),
    /**
     * 通过
     */
    REGULAR(new RegularPrice(), 0);
    /**
     * 最终结果
     */
    private Price price;
    /**
     * 状态码
     */
    private final int code;

    PriceEnum(Price price, int code) {
        this.price = price;
        this.code = code;
    }
    //获取金额
    public double getCharge(int dayRented) {
        return price.getCharge(dayRented);
    }

    public int getFrequentRenterPoints(int dayRented) {
        return price.getFrequentRenterPoints(dayRented);
    }

    public static PriceEnum getInstance(int code) {
        return Arrays.asList(PriceEnum.values()).parallelStream().
                filter(currentStatus -> currentStatus.code == code).findFirst().orElse(null);
    }

    public int getPriceCode() {
        return code;
    }

}
